View Javadoc

1   package org.naftulin.classpathexplorer.dublicate.imlp;
2   
3   import java.io.File;
4   import java.io.IOException;
5   import java.util.Enumeration;
6   import java.util.LinkedList;
7   import java.util.List;
8   import java.util.jar.JarEntry;
9   import java.util.jar.JarFile;
10  
11  import org.naftulin.classpathexplorer.AccessibleResource;
12  
13  
14  /***
15   * Represents a Jar - archive for accessible resources.
16   * @author henry naftulin
17   * @version 1.0
18   */
19  class JarArchive extends AccessibleArchive {
20  
21  	JarArchive(File file) {
22  		super(file);
23  	}
24  
25  	/***
26  	 * Returns all of the resources in this archive.
27  	 * @return all of the resources in this archive.
28  	 * @throws IOException if an error occurs while reading the content of 
29  	 *  the archive.
30  	 */
31  	public AccessibleResource[] getAccessibleResources() throws IOException {
32  		JarFile file = new JarFile(getPath());
33  		List resources = new LinkedList();
34  		Enumeration fileEnum = file.entries();
35  		while(fileEnum.hasMoreElements()) {
36  			JarEntry entry = (JarEntry) fileEnum.nextElement();
37  			if (!entry.isDirectory()) {
38  				resources.add(new AccessibleResourceImpl(entry, this));
39  			}
40  		}
41  		
42  		// TODO Auto-generated method stub
43  		AccessibleResource[] accessibleResources = new AccessibleResource[resources.size()];
44  		accessibleResources = (AccessibleResource[]) resources.toArray(accessibleResources);
45  		return accessibleResources;
46  	}
47  
48  	/***
49  	 * Returns the string representation of the resource.
50  	 * @return the string representation of the resource.
51  	 */
52  	public String toString() {
53  		StringBuffer sb = new StringBuffer(100);
54  		sb.append("Jar Archive[");
55  		sb.append(super.toString());
56  		sb.append("]\n");
57  		return sb.toString();
58  	}
59  	
60  	/***
61  	 * Returns the xml representation of the resource.
62  	 * @return the xml representation of the resource.
63  	 */
64  	public String toXml() {
65  		StringBuffer sb = new StringBuffer(100);
66  		sb.append("<jarArchive ");
67  		sb.append(super.toString());
68  		sb.append("/>\n");
69  		return sb.toString();
70  	}
71  }